home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / qbfaqr01.zip / QBREDIR.DOC < prev    next >
Text File  |  1992-08-10  |  3KB  |  79 lines

  1. 'Date: 02-06-92 (11:56)
  2. 'From: TONY ELLIOTT
  3. 'Subj: Pgm output redirection
  4. '---------------------------------------------------------------------------
  5. 'Hello everyone,
  6.  
  7. 'While writing a utility program for my company, there became a need to
  8. 'determine if the output of the program was being redirected to a file
  9. 'or another "non-visual" device. For example:
  10.  
  11. '        Program > Output.Fil
  12.  
  13. 'When typed at the DOS prompt, the above command will send all program
  14. 'output normally directed to the screen to the file "output.fil" instead
  15. '(this applies only to BASIC PRINT statements .. third-party asm screen
  16. 'writing routines' output cannot be redirected). In any event, if output
  17. 'was being redirected, I didn't want the utility to prompt the user for
  18. 'any keyboard input because the prompt wouldn't be seen! The program
  19. 'would just seem to lock up.
  20.  
  21. 'I wrote a little ASM routine that checks to see if output was being
  22. 'redirected, and if so, returns a value of -1 (TRUE) as a result of the
  23. 'function. For those interested, here it is. You'll need MASM 5.1 to
  24. 'assemble it ( masm redir; ). The resuting .OBJ can be used in QB4.x -
  25. 'PDS 7.1. Although it can be invoked harmlessly within the IDE, there's
  26. 'no way to redirect program output when it is running in the IDE.
  27.  
  28.     'Example program for REDIR.ASM
  29.  
  30.     DECLARE FUNCTION Redirected% ()
  31.  
  32.     IF Redirected% THEN                 'Since BEEP is redirected
  33.         FOR X% = 1 TO 3                 ' let's make some noise
  34.             FOR I = 400 TO 1000 STEP 40 ' using SOUND so we know
  35.                 SOUND I, I/1000         ' this routine works.
  36.             NEXT
  37.         NEXT
  38.         PRINT "This message will be sent to file or device targeted"
  39.         PRINT "by the > symbol."
  40.     ELSE
  41.         PRINT "Not redirected."
  42.     END IF
  43.  
  44. ;Different file here
  45.  
  46. ;The following is the assembly langauge source code for the Redirected%
  47. ;function. It's not compilcated, but it serves a useful purpose.
  48.  
  49. ; REDIR.ASM
  50. ; Redirected% - Returns -1 (TRUE) if the current program's output is
  51. ; being redirected. That is, the ">" was used on the DOS command line when
  52. ; the program was invoked:
  53. ;
  54. ;          Program > Output.TXT
  55. ;
  56.  
  57. .model medium, basic
  58. .code
  59.  
  60. Redirected proc
  61.  
  62.     mov ax,4400h                ;IOCTL - Get device info
  63.     mov bx,1                    ;For the "standard output device"
  64.     int 21h                     ;Call DOS
  65.     xor ax,ax                   ;Assume NOT redirected
  66.     test dl,16                  ;Is redirection active?
  67.     jnz @f                      ;If not, return 0 (false)
  68.     mov ax,-1                   ;If so, return (-1) true
  69. @@: ret                         ;[shouldn't the label be @F?]
  70.  
  71. Redirected endp
  72. end
  73.  
  74. ;--------End of assembly listing---------------------
  75.  
  76. ;For those of you without MASM 5.1, you can call my BBS (404-928-7111)
  77. ;and download this routine (source and .OBJ) and example program. It's
  78. ;in QBREDIR.ZIP.
  79.